package a18_SimplePracticeAll;

/**
 * @Author quan
 * @Description 将一个数组中的元素粘贴到另一个数组中去
 * @Date 2023/2/2 15:57
 */
public class A3_copyArrayToAnotherArray {
    public static void main(String[] args) {
        //-------------自己写的(for循环比较冗余) ----------
        //定义一个数组A
        /*int[] arr1 = {1,2,3,4,5};
        int[] arr2 = new int[arr1.length];
        for (int i = 0; i < arr1.length; i++) {
            for (int j = i; j <= i; j++) {
                arr2[j] = arr1[i];
            }
        }
        for (int i = 0; i < arr2.length; i++) {
            System.out.println(arr2[i]);
        }*/
        //-------------参考答案-------------
        int[] arr1 = {1,2,3,4,5};
        int[] arr2 = new int[arr1.length];
        for (int i = 0; i < arr1.length; i++) {
            arr2[i] = arr1[i];
        }
        for (int i = 0; i < arr2.length; i++) {
            System.out.println(arr2[i]);
        }
    }
}
